It's not correct to call endwin() if initscr() fails, and it crashes
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Tue, 17 Oct 2006 17:36:26 +0000 (18:36 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Tue, 17 Oct 2006 17:36:26 +0000 (18:36 +0100)
older libcurses implementations.

Signed-off-by: John Levon <john.levon@sun.com>
tools/xenstat/xentop/xentop.c

index 271f4b2bf7f1695b2c13bdcf0c93e753191304f8..7d3ec59d2ec56d2e58199c010c5dce491e67d16e 100644 (file)
@@ -187,6 +187,8 @@ char prompt_val[PROMPT_VAL_LEN];
 int prompt_val_len = 0;
 void (*prompt_complete_func)(char *);
 
+static WINDOW *cwin;
+
 /*
  * Function definitions
  */
@@ -223,7 +225,7 @@ static void version(void)
 /* Clean up any open resources */
 static void cleanup(void)
 {
-       if(!isendwin())
+       if(cwin != NULL && !isendwin())
                endwin();
        if(prev_node != NULL)
                xenstat_free_node(prev_node);
@@ -236,7 +238,7 @@ static void cleanup(void)
 /* Display the given message and gracefully exit */
 static void fail(const char *str)
 {
-       if(!isendwin())
+       if(cwin != NULL && !isendwin())
                endwin();
        fprintf(stderr, str);
        exit(1);
@@ -1029,7 +1031,7 @@ int main(int argc, char **argv)
 
        if (!batch) {
                /* Begin curses stuff */
-               initscr();
+               cwin = initscr();
                start_color();
                cbreak();
                noecho();